package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.SensitiveDto;
import com.heima.model.wemedia.dtos.WmSensitiveDto;
import com.heima.model.wemedia.pojos.WmSensitive;
import com.heima.wemedia.service.WmSensitiveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 敏感词信息表 前端控制器
 * </p>
 *
 * @author 一叠温酒
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/sensitive")
public class WmSensitiveController {

    @Autowired
    private WmSensitiveService wmSensitiveService;

    /**
     * 根据id删除
     *
     * @param id
     * @return
     */
    @DeleteMapping("/del/{id}")
    public ResponseResult delete(@PathVariable Integer id) {
        wmSensitiveService.removeById(id);
        return ResponseResult.okResult(200, "删除成功");
    }

    /**
     * 新增铭感词
     * @param wmSensitive
     * @return
     */
    @PostMapping("/save")
    public ResponseResult save(@RequestBody WmSensitive wmSensitive) {
        wmSensitive.setCreatedTime(new Date());
        wmSensitiveService.save(wmSensitive);
        return ResponseResult.okResult(200, "保存成功");
    }

    /**
     * 根据id修改
     * @param wmSensitive
     * @return
     */
    @PostMapping("update")
    public ResponseResult update(WmSensitive wmSensitive)
    {

       wmSensitiveService.updateById(wmSensitive);
       return ResponseResult.okResult(200,"修改成功");
   }

   @PostMapping("/list")
    public PageResponseResult list(@RequestBody() SensitiveDto sensitiveDto)
   {

       return wmSensitiveService.list(sensitiveDto);
   }
}
